<?php
function gender_porsion(){
load_graphic_model('pie3d');
$query = "
SELECT b.kelamin , COUNT(*) as total_record FROM karyawan a 
INNER JOIN biodata b ON a.biodata_id=b.biodata_id GROUP BY b.kelamin";
$result = my_query($query);
$data = array();
$label = array();
while($row = my_fetch_array($result)){
	$data[] = $row['total_record'];
	$label[] = $row['kelamin'];
} 
$graph = new PieGraph(280,190);
$graph->SetShadow();
 
$graph->title->Set("Perbandingan jumlah karyawan");
$graph->title->SetFont(FF_FONT1,FS_BOLD);
 
$p1 = new PiePlot3D($data);
$p1->SetTheme("water"); 
$p1->SetLegends($label);
$p1->SetAngle(50);
$p1->SetSize(0.5);
$p1->SetCenter(0.45);
//$p1->ExplodeAll(15);

$graph->legend->Pos(0.05,0.35);
$graph->legend->SetShadow(false);
$n = isset($n) ? $n : 0;  
for( $i=0; $i < $n; ++$i ) {
    $graph->Add($p[$i]);
}

 
$graph->Add($p1);
$graph->Stroke();
}

function get_total_by_gender_age($gender , $a,$b){
	$query = "SELECT COUNT( * ) AS TRT
			FROM karyawan a
			INNER JOIN biodata b ON a.biodata_id = b.biodata_id
			WHERE karyawan_id NOT
			IN (

			SELECT karyawan_id
			FROM karyawan_disable
			)
			AND kelamin = '{$gender}'
			AND (
			(
			YEAR( CURDATE( ) ) - YEAR( tanggal_lahir )
			) - ( RIGHT( CURDATE( ) , 5 ) < RIGHT( tanggal_lahir, 5 ) )
			BETWEEN {$a}
			AND {$b}
			) 
";
$result = my_query($query);
$row = my_fetch_array($result);
return $row['TRT'];
}

function sebaran_usia(){
load_graphic_model('bar');
$p1 = get_total_by_gender_age('laki-laki', 20,25);
$p2 = get_total_by_gender_age('laki-laki', 26,30);
$p3 = get_total_by_gender_age('laki-laki', 31,35);
$p4 = get_total_by_gender_age('laki-laki', 36,40);
$p5 = get_total_by_gender_age('laki-laki', 41,45);
$p6 = get_total_by_gender_age('laki-laki', 46,50);
$p7 = get_total_by_gender_age('laki-laki', 51,55); 
$p8 = get_total_by_gender_age('laki-laki', 56,150); 
//$data1y=array(12,8,10,6,3,7,8);
$data1y=array($p1,$p2,$p3,$p4,$p5,$p6,$p7,$p8);

$p1 = get_total_by_gender_age('perempuan', 20,25);
$p2 = get_total_by_gender_age('perempuan', 26,30);
$p3 = get_total_by_gender_age('perempuan', 31,35);
$p4 = get_total_by_gender_age('perempuan', 36,40);
$p5 = get_total_by_gender_age('perempuan', 41,45);
$p6 = get_total_by_gender_age('perempuan', 46,50);
$p7 = get_total_by_gender_age('perempuan', 51,55);  
$p8 = get_total_by_gender_age('laki-laki', 56,150); 
//$data2y=array(12,3,17,8,10,9,11); 
$data2y=array($p1,$p2,$p3,$p4,$p5,$p6,$p7,$p8); 
 
// Create the graph. These two calls are always required
$graph = new Graph(805,280);    
$graph->SetScale("textlin");
 
$graph->SetShadow();
$graph->img->SetMargin(40,30,20,40);
 
// Create the bar plots
$b1plot = new BarPlot($data1y);
$b1plot->SetFillColor("orange");
$b2plot = new BarPlot($data2y);
$b2plot->SetFillColor("blue");
 
// Create the grouped bar plot
$gbplot = new AccBarPlot(array($b1plot,$b2plot));
 
// ...and add it to the graPH
$graph->Add($gbplot);
 
$graph->title->Set("Sebaran usia karyawan");
$graph->xaxis->title->Set("Usia");
$lbl = array("20 - 25","26 - 30","31 - 35","36 - 40", "41 - 45", "46 - 50","50 - 55", " > 56");
 
$graph->xaxis->SetTickLabels($lbl);
$graph->yaxis->title->Set("Jumlah");
 
$graph->title->SetFont(FF_FONT1,FS_BOLD);
$graph->yaxis->title->SetFont(FF_FONT1,FS_BOLD);
$graph->xaxis->title->SetFont(FF_FONT1,FS_BOLD);
 
// Display the graph
$graph->Stroke();

}

function trend_lamaran(){
	load_graphic_model('line'); 
	// Some (random) data
	$ydata = array(11,3,8,12,5,1,9,13,5,7,11,6);
	$label = array('Jan','Feb','Mar','Apr','Mei','Jun','Jul', 'Agu' , 'Sep' ,'Okt' ,'Nop','Des');
	 
	// Size of the overall graph
	$width=805;
	$height=280;
	 
	// Create the graph and set a scale.
	// These two calls are always required
	$graph = new Graph($width,$height);
	$graph->SetScale('intlin');
	$graph->SetShadow();
	 
	// Setup margin and titles
	$graph->SetMargin(40,20,20,40);
	$graph->title->Set('Trend lamaran peminat kerja');
	$graph->subtitle->Set('(Tahun 2009)');
	$graph->xaxis->title->Set('Bulan');
	$graph->yaxis->title->Set('Jumlah');
	$graph->xaxis->SetTickLabels($label);

	 
	$graph->yaxis->title->SetFont( FF_FONT1 , FS_BOLD );
	$graph->xaxis->title->SetFont( FF_FONT1 , FS_BOLD );
	 
	$graph->yaxis->SetColor('blue');
	 
	// Create the linear plot
	$lineplot=new LinePlot($ydata);
	$lineplot->SetColor( 'blue' );
	$lineplot->SetWeight( 3 );   // Two pixel wide
	//$lineplot->mark->SetType(MARK_IMG_DIAMOND,'red',0.5);

	$lineplot->mark->SetColor('blue');
	$lineplot->mark->SetFillColor('red');
	$lineplot->value->SetFormat('(%d)');  
	$lineplot->value->Show();
	 
	// Add the plot to the graph
	$graph->Add($lineplot);
	 
	// Display the graph
	$graph->Stroke();

}